"""
下面的程序使用字典包含
其他字典，用于记录谁为野餐带来了什么食物。totalBrought()函数可以读取这个数
据结构，计算所有客人带来的食物的总数
"""

allGuests = {'Alice': {'apples': 5, 'pretzels': 12},
             'Bob': {'ham sandwiches': 3, 'apples': 2},
             'Carol': {'cups': 3, 'apple pies': 1}}


def totalBrought(guests, item):
    count = 0
    for k, v in guests.items():
        count = count + v.get(item, 0)
    return count


print(totalBrought(allGuests, "apples"))
print(totalBrought(allGuests, "pretzels"))
print(totalBrought(allGuests, "cups"))
